package com.wf.day_0531.test6;

import lombok.AllArgsConstructor;
import lombok.Data;

/**
 * @author mpk
 * @since 2024/5/31 18:06:53
 */

/*扩展：自定义TreeNode类 用代码实现二叉树的遍历
class TreeNode{
    private int value;
    private TreeNode left;
    private TreeNode right;

    public void preForeach(){} 前序
    public void midForeach(){} 中序
    public void postForeach(){} 后序
}*/
@Data
@AllArgsConstructor
public class TreeNode {

    private int value;
    private TreeNode left;
    private TreeNode right;

    public void preForeach() {

        System.out.println(this.value);

        if (left!= null) {
            left.preForeach();
        }

      if (right!=null) {
          right.preForeach();
      }
    }

    public void midForeach() {

        if (left!= null) {
            left.midForeach();
        }

        System.out.println(value);
        if(right!=null) {
            right.preForeach();
        }
    }

    public void postForeach() {

        if (left!= null) {
            left.postForeach();
        }

        if (right!= null) {
            right.postForeach();
        }

        System.out.println(value);

    }
}
